﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Common.Library;
using System.ComponentModel;
using OnlineVideos.Data;
using OnlineVideos.Common;
using System.Threading;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using OnlineVideos;
using OnlineVideos.UI;
using OnlineVideos.Utilities;
using Common.Utilities;
using OnlineVideos.Entities;



namespace OnlineVideos
{
    public partial class AudioFavorite : UserControl
    {
        #region GlobalDeclaration
        List<ShowLinks> showFavaudiosongs = null;
        List<ShowLinks> objAudioList;
        ShowAudio audio;
        #endregion

        #region Constructor
        public AudioFavorite()
        {
            InitializeComponent();
            objAudioList = new List<ShowLinks>();
            audio = new ShowAudio();
            GetPageDataInBackground();
        }
        #endregion

        #region "Common Methods"
        private void GetPageDataInBackground()
        {
            try
            {
                BackgroundHelper bwHelper = new BackgroundHelper();

                bwHelper.AddBackgroundTask(
                                                 (object s, DoWorkEventArgs a) =>
                                                 {
                                                     a.Result = FavoritesManager.GetFavoriteAudioLinks();
                                                 },
                                                 (object s, RunWorkerCompletedEventArgs a) =>
                                                 {
                                                     showFavaudiosongs = (List<ShowLinks>)a.Result;
                                                     if (showFavaudiosongs.Count > 0)
                                                     {
                                                         lbxFavoriteaudio.ItemsSource = showFavaudiosongs;
                                                         tblkFavNoAudio.Visibility = Visibility.Collapsed;
                                                     }
                                                     else
                                                     {
                                                         tblkFavNoAudio.Visibility = Visibility.Visible;
                                                         tblkFavNoAudio.Text = "No " + AppResources.ShowFavoriteAudioPivotTitle + " available";
                                                     }

                                                 }
                                               );

                bwHelper.RunBackgroundWorkers();
            }
            catch (Exception ex)
            {
                
               Exceptions.SaveOrSendExceptions("Exception in GetPageDataInBackground Method In AudioFavorite.cs file.", ex);
            }
        }
        #endregion

        #region Events
        private void lbxFavoriteaudio_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (lbxFavoriteaudio.SelectedIndex == -1)
                return;
            audio.LoadDownLoads(lbxFavoriteaudio.SelectedItem as ShowLinks);
            AppSettings.SongID = (lbxFavoriteaudio.SelectedItem as ShowLinks).LinkID.ToString();
            AppSettings.AudioImage = (lbxFavoriteaudio.SelectedItem as ShowLinks).Songplay;
            AppSettings.LinkTitle = (lbxFavoriteaudio.SelectedItem as ShowLinks).Title.ToString();
            AppSettings.LinkType = "Audio";
            objAudioList = FavoritesManager.GetFavoriteAudioLinks();
             lbxFavoriteaudio.ItemsSource = objAudioList;
            lbxFavoriteaudio.SelectedIndex = -1;
        }
        private void btnAudioFavSong_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                OnlineVideos.View_Models.ShowDetail detailModel = new OnlineVideos.View_Models.ShowDetail();
                detailModel.AddToFavorites(lbxFavoriteaudio, sender as MenuItem, LinkType.Audio);
                PageHelper.NavigateToMainPage(null, null);
            }
            catch (Exception ex)
            {
                Exceptions.SaveOrSendExceptions("Exception in btnAudioFavSong_Click Method In AudioFavorite.cs file.", ex);
            }
        }
        #endregion

    }
}
